package 优先算法.递归_搜索与回溯.综合案列.目标和;

public class Main {
}
class Solution {
    int path;
    int target;
    int count;
    public int findTargetSumWays(int[] nums, int _target) {
        target = _target;
        dfs(nums, 0);
        return count;
    }

    private void dfs(int[] nums, int start) {

        if(start == nums.length){
            if(path == target) count++;
            return;
        }

        //加法

        path += nums[start];
        dfs(nums, start+1);
        path -= nums[start];

        //减法
        path -= nums[start];
        dfs(nums, start+1);
        path += nums[start];

    }
}